package calculator.entities;
import exceptions.DivideByZeroException;
/**
 *
 * @author Dargor
 */
public class IntegerNumber extends MathEntity implements IMathEntity{
    private int _number;

    public IntegerNumber(int a)
    {
        this._number = a;
    }
    
    public IMathEntity add(IMathEntity a) {
        IntegerNumber operand = a.parseIntegerNumber();
        IntegerNumber result = new IntegerNumber(this._number + operand.getValue());
        return result;
    }

    public IMathEntity substract(IMathEntity a) {
        IntegerNumber operand = a.parseIntegerNumber();
        IntegerNumber result = new IntegerNumber(this._number - operand.getValue());
        return result;
    }

    public IMathEntity divide(IMathEntity a)throws DivideByZeroException {
        IntegerNumber operand = a.parseIntegerNumber();
        if(operand.getValue() == 0)
            throw new DivideByZeroException("Operand equals zero. Cannot divide.");

        IntegerNumber result = new IntegerNumber(this._number / operand.getValue());
        return result;
    }

    public IMathEntity multiply(IMathEntity a) {
        IntegerNumber operand = a.parseIntegerNumber();
        IntegerNumber result = new IntegerNumber(this._number * operand.getValue());
        return result;
    }

    public int getValue()
    {
        return this._number;
    }

    public IntegerNumber parseIntegerNumber() {
        return this;
    }

    public MyVector parseMyVector() {
        MyVector result = new MyVector(1);
        result.setAtPosition(0, this._number);
        return result;
    }

    public SuperBigNumber parseSuperBigNumber() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String toString() {
        return String.valueOf(this._number);
    }


}
